


package com.UMLife.me.global;

import java.io.IOException;
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.Item;
import javax.microedition.midlet.MIDlet;
import com.UMLife.me.model.AboutMeModel;
import com.UMLife.me.model.ForgetPswModel;
import com.UMLife.me.model.GetQuestionsModel;
import com.UMLife.me.model.LoginModel;
import com.UMLife.me.model.Registration;
import com.UMLife.me.ui.AboutItUI;
import com.UMLife.me.ui.AboutMeUI;
import com.UMLife.me.ui.AboutUsUI;
import com.UMLife.me.ui.ForgetPswUI;
import com.UMLife.me.ui.LoginUI;
import com.UMLife.me.ui.MainMenu;
import com.UMLife.me.ui.QuestionUI;
import com.UMLife.me.ui.RankUI;
import com.UMLife.me.ui.RegisterUI;
import com.UMLife.me.ui.TipsUI;
import de.enough.polish.ui.Alert;
import de.enough.polish.ui.Command;
import de.enough.polish.ui.Display;
import de.enough.polish.ui.ImageItem;





/**
 * <p>
 * Description
 * <p>
 * 这个类全部都是静态内容，目的是便利的共享。 共享的内容有：
 * <p>
 * 1.Display和MIDlet
 * <p>
 * 2.各个UI界面
 * <p>
 * 3.各个Model
 * <p>
 * 4.各种Command
 * <ul>
 * <li>1.这里采用单例设计模式，每个类有且只有一个对象。
 * <li>2.当这个对象尚未建立的时候，采用相应的getter函数可以创建一个新的UI；
 * <li>3.当这个对象已经建立的时候，采用相应的getter函数可以获取之前建立的UI;
 * <li>4.这个类的建立目的是为了防止重复建造对象，导致内存的浪费，因此尽量使用这些静态 方法，而不要单独使用构造函数.
 * <ul>
 */
public class Global
{
	public static AboutItUI getAboutItUI()
	{
		if (Global.aboutItUI == null)
		{
			Global.aboutItUI = new AboutItUI();
		}
		return Global.aboutItUI;
	}
	
	public static AboutMeModel getAboutMeModel()
	{
		if (Global.aboutMeModel == null)
		{
			Global.aboutMeModel = new AboutMeModel();
		}
		return Global.aboutMeModel;
	}
	
	public static AboutMeUI getAboutMeUI()
	{
		if (Global.aboutMeUI == null)
		{
			Global.aboutMeUI = new AboutMeUI();
		}
		return Global.aboutMeUI;
	}
	
	public static AboutUsUI getAboutUsUI()
	{
		if (Global.aboutUsUI == null)
		{
			Global.aboutUsUI = new AboutUsUI();
		}
		return Global.aboutUsUI;
	}
	
	public static Command getCmdBack()
	{
		if (Global.cmdBack == null)
		{
			Global.cmdBack = new Command("后退", Command.BACK, 1);
			
		}
		return Global.cmdBack;
	}
	
	public static Command getCmdCancel()
	{
		if (Global.cmdCancel == null)
		{
			Global.cmdCancel = new Command("取消", Command.CANCEL, 1);
		}
		return Global.cmdCancel;
	}
	
	public static Command getCmdExit()
	{
		if (Global.cmdExit == null)
		{
			Global.cmdExit = new Command("退出", Command.EXIT, 1);
		}
		return Global.cmdExit;
	}
	
	public static Command getCmdOk()
	{
		if (Global.cmdOk == null)
		{
			Global.cmdOk = new Command("确定", Command.OK, 1);
		}
		return Global.cmdOk;
	}
	
	public static Command getCommandNext()
	{
		if (Global.cmdNext == null)
		{
			Global.cmdNext = new Command("退出", Command.SCREEN, 1);
		}
		return Global.cmdNext;
	}
	
	public static ForgetPswModel getForgetPswModel()
	{
		if (Global.forgetPswModel == null)
		{
			Global.forgetPswModel = new ForgetPswModel();
		}
		return Global.forgetPswModel;
	}
	
	public static ForgetPswUI getForgetPswUI()
	{
		if (Global.forgetPswUI == null)
		{
			Global.forgetPswUI = new ForgetPswUI();
		}
		return Global.forgetPswUI;
		
	}
	
	public static Display getGlobalDisplay()
	{
		return Global.globalDisplay;
	}
	
	public static ImageItem getGlobalLogo()
	{
		if (Global.globalLogo == null)
		{
			try
			{
				Image img = Image.createImage("/logo.png");
				Global.globalLogo = new ImageItem("", img, Item.LAYOUT_EXPAND,
						"logo");
			} catch (IOException e)
			{
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		}
		
		return Global.globalLogo;
	}
	
	public static MIDlet getGlobalMIDlet()
	{
		return Global.globalMIDlet;
	}
	
	public static LoginModel getLoginModel()
	{
		if (Global.loginModel == null)
		{
			Global.loginModel = new LoginModel();
		}
		return Global.loginModel;
	}
	
	public static LoginUI getLoginUI()
	{
		if (Global.loginUI == null)
		{
			Global.loginUI = new LoginUI();
		}
		return Global.loginUI;
	}
	
	public static MainMenu getMainMenu()
	{
		if (Global.mainMenu == null)
		{
			Global.mainMenu = new MainMenu();
		}
		return Global.mainMenu;
	}
	
	public static GetQuestionsModel getQuestionModel()
	{
		if (Global.questionModel == null)
		{
			Global.questionModel = new GetQuestionsModel();
		}
		return Global.questionModel;
	}
	
	public static QuestionUI getQuestionUI()
	{
		if (Global.questionUI == null)
		{
			Global.questionUI = new QuestionUI();
		}
		return Global.questionUI;
	}
	
	public static RankUI getRankUI()
	{
		if (Global.rankUI == null)
		{
			Global.rankUI = new RankUI();
		}
		return Global.rankUI;
	}
	
	public static RegisterUI getRegisterUI()
	{
		if (Global.registerUI == null)
		{
			Global.registerUI = new RegisterUI();
		}
		return Global.registerUI;
	}
	
	public static Registration getRegistMode()
	{
		if (Global.registModel == null)
		{
			Global.registModel = new Registration();
		}
		return Global.registModel;
	}
	
	public static Alert getTestAlert()
	{
		if (Global.testAlert == null)
		{
			Global.testAlert = new Alert("测试说明：");
			Global.testAlert.setInfo("由于目前网络功能无法使用，无法获得服务器信息，出于测试的需，现在予以简化处理。");
		}
		return Global.testAlert;
	}
	
	public static TipsUI getTipsUI()
	{
		if (Global.tipsUI == null)
		{
			Global.tipsUI = new TipsUI();
		}
		return Global.tipsUI;
	}
	
	public static void setGlobalDisplay(Display globalDisplay)
	{
		Global.globalDisplay = globalDisplay;
	}
	
	public static void setGlobalLogo(ImageItem logoItem)
	{
		Global.globalLogo = logoItem;
	}
	
	public static void setGlobalMIDlet(MIDlet globalMIDlet)
	{
		Global.globalMIDlet = globalMIDlet;
	}
	
	private static AboutItUI			aboutItUI;
	
	private static AboutMeModel			aboutMeModel;
	
	private static AboutMeUI			aboutMeUI;
	
	private static AboutUsUI			aboutUsUI;
	
	private static Command				cmdBack;
	
	private static Command				cmdCancel;
	
	private static Command				cmdExit;
	
	private static Command				cmdNext;
	
	private static Command				cmdOk;
	
	private static ForgetPswModel		forgetPswModel;
	
	private static ForgetPswUI			forgetPswUI;
	
	private static Display				globalDisplay;
	
	private static ImageItem			globalLogo;
	
	private static MIDlet				globalMIDlet;
	
	private static LoginModel			loginModel;
	
	private static LoginUI				loginUI;
	
	private static MainMenu				mainMenu;
	
	private static GetQuestionsModel	questionModel;
	
	private static QuestionUI			questionUI;
	
	private static RankUI				rankUI;
	
	private static RegisterUI			registerUI;
	
	private static Registration			registModel;
	
	private static Alert				testAlert;
	
	private static TipsUI				tipsUI;
	
}
